home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / ISR.SWG / 0003_ISRDEMO.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  111 lines

  1. {
  2. It can make sense to Write Method-ISR's. Two examples:
  3.  
  4. 1. Implementation of a timer-IRQ-triggered eventQueue (a body of such an
  5. Object I append to this mail).
  6.  
  7. 2. Objects For serial-IO. You can have up to 8 or 16 serial channels (with
  8. special hardware). The priciples of encapsulation and instances suggests
  9. an OOPS-solution! Why not including the ISR-Routine into the Object?
  10. I'm not happy about the intentional misunderstandings to your request
  11. in this area :-|
  12.  
  13. However, the next 2K are my act of revenge to your repliers: :-D
  14. (Gentlemen: No flames please, I know that the demo itself makes no sense
  15. and procedural Programming For such a simple output would be easier
  16. and shorter!!! All I want to show, is a toRSO of an OOPS-solution For ISR's.)
  17. }
  18.  
  19. Program isrDemo;
  20. {$F+,S-}
  21. Uses
  22.     Crt,Dos;
  23. Type
  24.     timerObj  =    Object
  25.                         saveInt,
  26.                         myjob     :    Pointer;
  27.                         stopped   :    Boolean;
  28.                         Constructor Init(job:Pointer);
  29.                         Destructor  DeInit;
  30.                         PRIVATE
  31.                         Procedure   timerInt;
  32.                    end;
  33. Const
  34.     timerSelf :    Pointer   =    NIL;
  35.  
  36. Constructor timerObj.Init(job:Pointer);
  37. begin
  38.     if timerSelf<>NIL then FAIL;            { only one instance in this demo }
  39.     timerSelf:=@self;
  40.     myjob:=job;
  41.     stopped:=False;
  42.     getintvec($1C,saveInt);
  43.     setintvec($1C,@timerObj.timerInt);
  44. end;
  45.  
  46. Destructor timerObj.DeInit;
  47. begin
  48.     setintvec($1C,saveint); timerSelf:=NIL;
  49. end;
  50.  
  51. Procedure timerObj.timerInt; Assembler;
  52. Label
  53.     _10;
  54. Asm
  55.     pop  bp                           { Compiler inserts PUSH BP - restore it }
  56.     push ax
  57.     push bx
  58.     push cx
  59.     push dx
  60.     push si
  61.     push di
  62.     push ds
  63.     push es
  64.     push bp
  65.     mov  al,20h                        { send EOI }
  66.     out  20h,al
  67.     sti
  68.  
  69.     mov  bp,sp
  70.     mov  ax,SEG @DATA
  71.     mov  ds,ax
  72.     les  di,[offset timerSelf]         { only one instance in this demo! }
  73.     cmp  es:[di+stopped],0             { prevents IRQ-overruns           }
  74.     jne  _10
  75.     inc  es:[di+stopped]
  76.     call dWord ptr es:[di+offset myjob]; { no test of NIL implemented    }
  77.     les  di,[offset timerSelf]
  78.     dec  es:[di+stopped]
  79.  
  80.    _10:
  81.     call dWord ptr es:[di+saveInt]     { call original inT-Proc }
  82.     mov  sp,bp
  83.     pop  bp
  84.     pop  es
  85.     pop  ds
  86.     pop  di
  87.     pop  si
  88.     pop  dx
  89.     pop  cx
  90.     pop  bx
  91.     pop  ax
  92.     iret
  93. end;
  94. (*********************** DemoShell **************************)
  95. Var
  96.     timer     :    timerObj;
  97.  
  98. Procedure helloHerb;
  99. begin
  100.     Write('.');
  101. end;
  102.  
  103. begin
  104.     if timer.Init(@helloHerb) then
  105.     begin
  106.          Delay(5000);
  107.          timer.DeInit;
  108.     end;
  109. end.
  110.  
  111.